package common.splitpage.template;

public class BaseTemplate {
	protected String context;
	
	protected void setLineBreak(StringBuffer sb){
		sb.append("\n");
	}
	
	protected void setTitleHtml(StringBuffer sb,String title){
		sb.append("<title>");
		sb.append(title);
		sb.append("</title>");
		this.setLineBreak(sb);
	}
	
	protected void setImportHtml(StringBuffer sb){
		String commonPath = "/common";
		this.startScript(sb);
		sb.append("function getRelationContext(){return '';}");
		sb.append("var commonPath='/common';");
		sb.append("var componentPath='/component';");
		this.endScript(sb);
		this.setLineBreak(sb);
		sb.append("<script src='"+commonPath+"/js/import.js'></script>");
		this.setLineBreak(sb);
	}
	
	protected void setCommonCss(StringBuffer sb){
		sb.append("<link rel='stylesheet' href='/css/common.css' />");
		this.setLineBreak(sb);
	}
	
	protected void setHeadHtml(StringBuffer sb,String title,String importLib){
		sb.append("<head>");
		this.setLineBreak(sb);
		sb.append("<title>"+title+"</title>");
		this.setLineBreak(sb);
		sb.append("<style>");
		sb.append("</style>");
		sb.append("</head>");
		this.setLineBreak(sb);
	}
	
	protected void setButtonHtml(StringBuffer sb,String value,String onClick){
		sb.append("<input type='button' value='" + value + "' class='btn_normal' onclick=\"" + onClick + "\" />&nbsp;");
		this.setLineBreak(sb);
	}
	protected void setButtonHtml(StringBuffer sb,String id,String value,String onClick){
		sb.append("<input type='button' id='"+id+"' value='" + value + "' class='btn_normal' onclick=\"" + onClick + "\" />&nbsp;");
		this.setLineBreak(sb);
	}
	protected void setButtonHtml(StringBuffer sb,String id,String name,String value,String onClick){
		sb.append("<input type='button' id='"+id+"' name='"+name+"' value='" + value + "' class='btn_normal' onclick=\"" + onClick + "\" />&nbsp;");
		this.setLineBreak(sb);
	}
	
	protected void startHtml(StringBuffer sb){
		sb.append("<html>");
		this.setLineBreak(sb);
	}
	protected void endHtml(StringBuffer sb){
		sb.append("</html>");
	}
	
	protected void startBody(StringBuffer sb,String attribute){
		sb.append("<body ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endBody(StringBuffer sb){
		sb.append("</body>");
		this.setLineBreak(sb);
	}
	
	protected void startForm(StringBuffer sb,String attribute){
		sb.append("<form ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endForm(StringBuffer sb){
		sb.append("</form>");
		this.setLineBreak(sb);
	}
	
	protected void startDiv(StringBuffer sb,String attribute){
		sb.append("<div ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endDiv(StringBuffer sb){
		sb.append("</div>");
		this.setLineBreak(sb);
	}
	
	protected void startTable(StringBuffer sb,String attribute){
		sb.append("<table ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endTable(StringBuffer sb){
		sb.append("</table>");
		this.setLineBreak(sb);
	}
	
	protected void startTr(StringBuffer sb,String attribute){
		sb.append("<tr ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endTr(StringBuffer sb){
		sb.append("</tr>");
		this.setLineBreak(sb);
	}
	
	protected void startTd(StringBuffer sb,String attribute){
		sb.append("<td ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endTd(StringBuffer sb){
		sb.append("</td>");
		this.setLineBreak(sb);
	}
	
	protected void startA(StringBuffer sb,String attribute){
		sb.append("<a ");
		sb.append(attribute);
		sb.append(">");
		this.setLineBreak(sb);
	}
	protected void endA(StringBuffer sb){
		sb.append("</a>");
		this.setLineBreak(sb);
	}
	
	protected void startScript(StringBuffer sb){
		this.setLineBreak(sb);
		sb.append("<SCRIPT LANGUAGE='JavaScript'>");
		this.setLineBreak(sb);
		sb.append("<!--");
		this.setLineBreak(sb);
	}
	protected void endScript(StringBuffer sb){
		this.setLineBreak(sb);
		sb.append("//-->");
		this.setLineBreak(sb);
		sb.append("</SCRIPT>");
		this.setLineBreak(sb);
	}
	
	protected void startMethod(StringBuffer sb,String methodName,String methodArgs){
		sb.append("function " + methodName + "(" + methodArgs + "){");
		this.setLineBreak(sb);
	}
	protected void endMethod(StringBuffer sb){
		sb.append("}");
		this.setLineBreak(sb);
	}
	
	protected void writeMethod(StringBuffer sb,String methodName,String content){
		sb.append("function " + methodName + "(){");
		this.setLineBreak(sb);
		sb.append(content);
		this.setLineBreak(sb);
		sb.append("}");
		this.setLineBreak(sb);
	}
	
	protected void setTry(StringBuffer sb){
		sb.append("try{");
		this.setLineBreak(sb);
	}
	protected void setCatch(StringBuffer sb,String error){
		sb.append("}catch(e){");
		this.setLineBreak(sb);
		sb.append(error);
		this.setLineBreak(sb);
		sb.append("}");
		this.setLineBreak(sb);
	}
	
	protected void windowClose(StringBuffer sb){
		sb.append("window.close();");
		this.setLineBreak(sb);
	}
	
	//��ȡjs����ʼ
	protected String windowUtil = "windowUtil";
	protected void setWindowUtil(StringBuffer sb){
		sb.append("var windowUtil = common.ObjectFactory.getInstance().getWindowUtil();");
		this.setLineBreak(sb);
	}
	//��ȡjs�������

	public String getContext() {
		return context;
	}

	public void setContext(String context) {
		this.context = context;
	}
	
}
